<template>
  <view class="container">
    <map
      :longitude="longitude"
      :latitude="latitude"
      :scale="14"
      :markers="markers"
      style="width: 100%; height: 600rpx"
      show-location
    />
  </view>
</template>

<script>
import amapFile from '@/utils/amap-wx.js'; // 路径按实际项目调整

export default {
  data() {
    return {
      longitude: 0,
      latitude: 0,
      markers: [],
    };
  },
  onLoad() {
    this.getLocationAndMarkers();
  },
  methods: {
    getLocationAndMarkers() {
      const myAmapFun = new amapFile.AMapWX({ key: 'a218db38f4a415b5789dfac8abc0396b' });

      // 获取当前位置周边 POI
      myAmapFun.getPoiAround({
        success: (res) => {
          if (res.markers.length) {
            this.latitude = res.markers[0].latitude;
            this.longitude = res.markers[0].longitude;
            this.markers = res.markers;
          }
        },
        fail: (err) => {
          console.log('地图加载失败', err);
        },
      });
    },
  },
};
</script>

<style>
.container {
  padding: 20rpx;
}
</style>
